package com.banmao.desktoptools.copyfilesScene;

import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.util.ArrayList;

@Data
public class FilePojo {

    private File file;

    private ArrayList<FilePojo> children = new ArrayList<>();

    public FilePojo(File file) {
        this.file = file;
    }

    public ArrayList<String> getChildrenNames() {
        ArrayList<String> childrenNames = new ArrayList<>();

        children.stream().sorted((vo1, vo2) -> {
            String name1 = vo1.getFile().getName();
            String name2 = vo1.getFile().getName();
            if (CollectionUtils.isNotEmpty(vo1.getChildren()) && CollectionUtils.isNotEmpty(vo2.getChildren())) {
                // 两个都是文件夹,按照名称顺序排序
                int compare = StringUtils.compare(name1, name2);
                return compare;
            } else {
                if (CollectionUtils.isNotEmpty(vo1.getChildren()) && CollectionUtils.isEmpty(vo2.getChildren())) {
                    // 1是文件夹
                    return -1;
                } else if (CollectionUtils.isEmpty(vo1.getChildren()) && CollectionUtils.isNotEmpty(vo2.getChildren())) {
                    return 1;
                } else {
                    return 0;
                }
            }
        }).forEach((vo1) -> {
            childrenNames.add(vo1.getFile().getName());
        });

        return childrenNames;

    }

}
